package com.shizhanzhe.zxbapp.my;

import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.gyf.barlibrary.ImmersionBar;
import com.shizhanzhe.zxbapp.R;
import com.shizhanzhe.zxbapp.bean.CooperBean;
import com.shizhanzhe.zxbapp.url.Path;
import com.shizhanzhe.zxbapp.utils.OkHttpDownloadJsonUtil;


import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class CooperationActivity extends AppCompatActivity {

    @BindView(R.id.top_title)
    TextView topTitle;
    @BindView(R.id.tv_kf)
    TextView tvKf;
    @BindView(R.id.tv_sw)
    TextView tvSw;
    @BindView(R.id.tv_gw)
    TextView tvGw;
    private String kfwx = "";
    private String swwx = "";
    private String gw = "";
    private ClipboardManager cm;
    private CooperBean data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cooperation);
        ButterKnife.bind(this);
        ImmersionBar.with(this)
                .fitsSystemWindows(true)  //使用该属性,必须指定状态栏颜色
                .statusBarColor(R.color.colorAccent)
                .init();
        initData();
    }

    private void initData() {
        topTitle.setText("商务合作");
        coop();
    }

    @OnClick({R.id.top_back, R.id.kfwx, R.id.swwx, R.id.gw})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.top_back:
                finish();
                break;
            case R.id.kfwx:
                cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                cm.setText(kfwx);
                Toast.makeText(this, "复制成功", Toast.LENGTH_SHORT).show();
                break;
            case R.id.swwx:
                cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                cm.setText(swwx);
                Toast.makeText(this, "复制成功", Toast.LENGTH_SHORT).show();
                break;
            case R.id.gw:
                cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                Toast.makeText(this, "复制成功", Toast.LENGTH_SHORT).show();
                cm.setText(gw);
                break;
        }
    }

    private void coop() {
        OkHttpDownloadJsonUtil.downloadJson(this, Path.businessCooperation,
                new OkHttpDownloadJsonUtil.onOkHttpDownloadListener() {
                    @Override
                    public void onsendJson(String json) {
                        if (!"1".equals(json) && !"0".equals(json)) {
                            try {
                                Gson gson = new Gson();
                                data = gson.fromJson(json, CooperBean.class);
                                kfwx = data.getData().getServicewx();
                                swwx = data.getData().getBusinwx();
                                gw = data.getData().getOffweb();
                                tvKf.setText("客服微信：" + kfwx);
                                tvSw.setText("商务微信：" + swwx);
                                tvGw.setText("官网：" + gw);
                            }catch (Exception e){}
                        }
                    }
                });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ImmersionBar.with(this).destroy();
    }
}
